package com.bailong.nanny.dao.impl;

import com.bailong.nanny.d.NannyDao;
import com.bailong.nanny.entity.Nanny;
import com.bailong.nanny.entity.dto.NannyWorkDTO;
import com.bailong.nanny.util.JdbcUtils;

import java.util.List;

public class NannyDaoImpl implements NannyDao {
    @Override
    public List<Nanny> selectAllNanny() {
        return JdbcUtils.queryList(NannyDao.class,"select * from tb_nanny");
    }

    @Override
    public int deleteNanny(int id) {
        return JdbcUtils.update("DELETE FROM tb_nanny WHERE user_id = ?",id);
    }

    @Override
    public int updateNanny(Nanny nanny) {
        return 0;
    }

    @Override
    public int addNanny(Nanny nanny) {
        return JdbcUtils.update("insert into tb_user(username,realname,address,tel)values(?,?,?,?)");
    }
String sql = "select n.name nannyName,count(*) workCount from tb_nanny n,tb_work w " + "where n.nanny_id=w.nanny_id group by n.nanny_id";
    @Override
    public List<NannyWorkDTO> selectAllNannyWork() {
        return JdbcUtils.queryList(NannyWorkDTO.class,sql);
//        return JdbcUtils.queryList(NannyWorkDTO.class,
//                "select t1.name,count(t2.work_id) from tb_nanny t1 left join tb_work t2 on t1.nanny_id=t2.nanny_id group by t1.nanny_id");
    }
}
